/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package isvp.constants;

import isvp.utilities.XMLUtils;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.HashMap;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

/**
 * Constant  relating to the ISVP are stored here
 * @author jjophin
 */
public class ISVPConstants {
    //base file name
    public static final String ISV_XML_FILE = "isv.xml";
    
    private static final HashMap<String, String> componentXPathMap = new HashMap<String, String>();
    
    public static final String APPLICATION = "Application";
    public static final String PRIVILEGES = "Privileges";
    public static final String ISVP_NAME_XPATH = "/ISVPackage/description/cn";
    public static final String ISVP_UPDATE_VERSION_XPATH = "/ISVPackage/content/UCImporter/Version";
    public static final String ISVP_COMPONENTS_XPATH = "/ISVPackage/content/UCImporter/Applications/Application";
    
    static {
        componentXPathMap.put(APPLICATION, "/ISVPackage/content/UCImporter/Applications/Application/Applications/FileName");
        componentXPathMap.put(PRIVILEGES, "/ISVPackage/content/UCImporter/Applications/Application/Privileges/FileName");
    }
    
    public static String getXPath(String componentName) {
        return componentXPathMap.get(componentName);
    }
    
    //String related to Add Application Request
    private static final String ADD_APPLICATION_REQUEST_FILE = "Add Organization.xml";//System.getProperty("user.dir") + "\\src\\isvp\\constants\\Add Organization.xml";
    public static final String ADD_APPLICATION_REQUEST = getApplicationRequest();
    public static final String REQUEST_BUSINESS_PARTNER_NAME = "\\{BusinessPartnerName\\}";
    public static final String REQUEST_APPLICATION_ID = "\\{ApplicationId\\}";
    public static final String REQUEST_PRIVILEGE_ID = "\\{PrivilegeId\\}";
    public static final String REQUEST_CLUSTER_NAME = "\\{ClusterName\\}";
    public static final String REQUEST_ISV_NAME = "\\{IsvName\\}";
    public static final String REQUEST_APPLICATION_NAME = "\\{ApplicationName\\}";
    public static final String REQUEST_APPLICATION_DESCRIPTION = "\\{ApplicationDescription\\}";
    
    public static String getApplicationRequest() {
        String xmlString = null;
        try {
            InputStream iStream = ISVPConstants.class.getResourceAsStream(ADD_APPLICATION_REQUEST_FILE);
            Document doc = XMLUtils.getXMLDocument(iStream);
            xmlString = XMLUtils.getXMLString(doc);
        } catch (SAXException ex) {
        }
        return xmlString;
    }
}